<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">

<section class="content-header">
    <h1>工艺卡提交</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-special">类型</label>
                                    <select id="query-special" class="form-control" name="special">
                                        <option value="" selected>请选择</option>
                                        <option th:each="type : ${specials}" th:value="${type.name}"
                                                th:text="${type.name}"></option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-part">部分</label>
                                    <input id="query-part" type="text" name="part" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-status">状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="">请选择</option>
                                        <option value="1" selected>待提交</option>
                                        <option value="2">待转定额</option>
                                        <option value="3">待定额提交</option>
                                        <option value="4">待转生产</option>
                                        <option value="5">已转生产</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-isCheck">审核状态</label>
                                    <select id="query-isCheck" class="form-control" name="isCheck">
                                        <option value="" selected>请选择</option>
                                        <option value="0">未审核</option>
                                        <option value="1">已审核</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-drawNo">图号</label>
                                    <input id="query-drawNo" type="text" name="drawNo" class="form-control"
                                           placeholder="请输入图号">
                                </div>
                                <div class="form-group">
                                    <label for="query-drawName">图名</label>
                                    <input id="query-drawName" type="text" name="drawName" class="form-control"
                                           placeholder="请输入图名">
                                </div>
                                <!--<div class="form-group">
                                    <label for="query-createName">工艺员</label>
                                    <input id="query-createName" type="text" name="createName" class="form-control"
                                           placeholder="请输入工艺员">
                                </div>
                                <div class="form-group">
                                    <label for="query-branchName">工艺科室</label>
                                    <input id="query-branchName" type="text" name="branchName" class="form-control"
                                           placeholder="请输入工艺科室">
                                </div>-->
                                <div class="form-group">
                                    <label for="query-startTime">日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker" name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <div id="toolbar" class="form-inline">
                        <a id="btn_notRead" shiro:hasPermission="est:cardList:commit" href="javascript:void(0);"
                           class="btn btn-success pull-right" style="margin-right: 10px" onclick="commitAll()">
                            <span class="Bold">批量提交</span>
                        </a>
                    </div>
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;

    /** 删除 */
    function delCard(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "est/cardList/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 作废 */
    function delSheetCard(id) {
        js.modal.confirm("确认删除吗？", function () {
            js.post({
                url: ctx + "est/cardList/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }

    /** 提交 */
    function commitCard(id) {
        js.modal.confirm("确认提交吗？", function () {
            js.post({
                url: ctx + "est/cardList/commit",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }



    /** 批量提交 */
    function commitAll() {
        let arr = js.table.selectColumns(table, "id");
        if (arr.length < 1) {
            js.modal.alert("请选择要提交的内容");
            return;
        }
        js.post({
            url: ctx + "est/cardList/commitAll",
            data: {
                ids: arr
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    js.modal.success(result.msg);
                    js.table.refresh(table);
                } else {
                    js.modal.warning(result.msg);
                }
            }
        })
    }

    $(function () {
        /** 计划单列表 */
        table = js.table.init({
            url: ctx + "est/cardList/list",
            columns: [
                {
                    checkbox: true,
                    formatter: function (value, row) {
                        if (row.status === 1) {
                            return {disabled: false}
                        } else {
                            return {disabled: true}
                        }
                    }
                },
                {
                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'
                    // ,width: '260px'
                },
                {title: "项目<br>数量", field: 'proNum'},
                {title: "类型", field: 'special'},
                {title: "部分", field: 'part'},
                {title: "图号", field: 'drawNo'},
                {title: "图名", field: 'drawName'},
                {title: "状态", field: 'status',
                    formatter: function (value, row) {
                        if (value === 1) {
                            return '<span class="badge label-inverse">待提交</span>';
                        } else if (value === 2) {
                            return '<span class="badge label-warning">待转定额</span>';
                        } else if (value === 3) {
                            return '<span class="badge label-warning">待定额提交</span>';
                        } else if (value === 4) {
                            return '<span class="badge label-warning">待转生产</span>';
                        } else if (value === 5) {
                            return '<span class="badge label-success">已转生产</span>';
                        }
                    }
                },
                {title: "审核<br>状态", field: 'isCheck',
                    formatter: function (value) {
                        if (value === 0) {
                            return '<span class="badge label-default">未审核</span>';
                        } else if (value === 1) {
                            return '<span class="badge label-success">已审核</span>';
                        }
                    }
                },
                // {title: "工艺科室", field: 'branchName'},
                // {title: "创建人", field: 'createNameOne'},
                {title: "审核人", field: 'verifyName'},
                {title: "提报日期", field: 'createTime', width: '100px'},
                {title: "驳回原因", field: 'rejectReason',
                    formatter: function (value, row) {
                        if (value) {
                            return '<span class="text-red">' + value + '</span>';
                        }
                    }
                },
                {
                    title: "操作",
                    // width: '160px',
                    formatter: function (value, row) {
                        let actions = [];
                        if (row.status !== 1) {
                            actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'est/cardList/' + row.id + '" > 查看</a>');
                        }
                        if (hasP('est:cardList:edit') && row.status === 1 ) {
                            actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'est/cardList/edit/' + row.id + '" > 编辑</a>');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delCard(' + row.id + ')"> 删除</a>');
                        }
                        if (hasP('est:cardList:commit') && row.status === 1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="commitCard(' + row.id + ')"> 提交</a>');
                        }
                        if (hasP('est:cha:edit') && row.status === 5) {
                            actions.push('<a class="btn btn-warning btn-xs" target="_blank" href="' + ctx + 'est/cha/edit/' + row.id + '" > 变更</a>');
                        }
                        if(row.status === 5 && row.craDel === 1){
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="delSheetCard(' + row.id + ')"> 作废</a>');
                        }
                        /*if (hasP('est:cardList:cha')) {
                            actions.push('<a class="btn btn-warning btn-xs" href="' + ctx + 'report/list/select/' + row.id + '" > 变更</a>');
                        }*/
                        return actions.join('');
                    }
                }
            ]
        });

    });
</script>
</body>
</html>
